<template>
  <div>
    <div class="header">
      <div class="header-main">
        <div class="header-left">
          <a href="" class="header-imgWrapper">
            <img
              class="header-img"
              src="https://www.kugou.com/common/images/kugou_white.png"
              alt=""
            />
          </a>
          <div class="search-wrapper">
            <div class="search-input"></div>
            <div class="search-icon">
              <i class="iconfont icon-search"></i>
            </div>
          </div>
        </div>
        <div class="header-right">
          <a target="_blank" href="">音乐人</a>
          <a target="_blank" href="">音频制作</a>
          <a target="_blank" href="">开放平台</a>
          <a target="_blank" href="">VIP会员</a>
          <a target="_blank" href="" class="line">|</a>
          <div class="login-wrapper" v-if="!userInfo.nickname">
            <div class="login" @click="login">登录</div>
          </div>
          <div class="login-wrapper" v-else>
            <img :src="userInfo.avatarUrl" alt="" />
            <span>{{ userInfo.nickname }}</span>
          </div>
        </div>
      </div>
    </div>
    <div class="nav-wrapper">
      <ul class="nav" @click="isShow">
        <li :class="defaultIndex === '0' ? 'active' : ''">
          <router-link to="/home" data-index="0">首页</router-link>
        </li>
        <li :class="defaultIndex === '1' ? 'active' : ''">
          <router-link to="/RankList" data-index="1">榜单</router-link>
        </li>
        <li :class="defaultIndex === '2' ? 'active' : ''">
          <router-link to="/MusicVideo" data-index="2">MV</router-link>
        </li>
        <li :class="defaultIndex === '3' ? 'active' : ''">
          <router-link to="/songSheet" data-index="3">歌单</router-link>
        </li>
        <li :class="defaultIndex === '4' ? 'active' : ''">
          <router-link to="/singer" data-index="4">歌手</router-link>
        </li>
        <li :class="defaultIndex === '5' ? 'active' : ''">
          <router-link to="/Album" data-index="5">专辑</router-link>
        </li>
        <li>
          <a>更多</a>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "Header",
  data() {
    return {
      isShowLogin: false,
      defaultIndex: "0",
    };
  },
  methods: {
    login() {
      this.$bus.$emit("show", true);
    },
    isShow(e) {
      const index = e.target.dataset.index;
      this.defaultIndex = index;
    },
  },
  // 获取用户信息
  computed: {
    ...mapState({
      userInfo: (state) => {
        return state.user.userInfo;
      },
    }),
  },
};
</script>

<style lang="less" scoped>
html,
body {
  width: 100%;
}
.header {
  width: 100%;
  height: 80px;
  background-color: #00a9ff;
}

.header-main {
  width: 1000px;
  margin: 0 auto;
  height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left {
  display: flex;
  width: 466px;
  height: 38px;
  justify-content: space-between;
  align-items: center;
}

.header-imgWrapper {
  width: 186px;
  height: 38px;
}

.header-img {
  width: 146px;
  height: 38px;
}

.search-wrapper {
  position: relative;
  width: 280px;
  height: 30px;
  border-radius: 31px;
  background: rgb(77, 194, 255);
}

.icon-search {
  position: absolute;
  width: 18px;
  height: 18px;
  left: 13px;
  font-weight: 700px;
  top: 5px;
  font-size: 17px;
  color: #caedff;
}

.header-right {
  display: flex;
  width: 490px;
  height: 30px;
  line-height: 30px;
  color: #fff;
}

.header-right a {
  font-size: 14px;
  color: #e5f6ff;
  margin-right: 32px;
}

.header-right .line {
  width: 1px;
  height: 14px;
  margin-right: 0;
}

.login-wrapper {
  display: flex;
  justify-content: center;
  width: 154px;
}

.login-wrapper img {
  border-radius: 50%;
}

.login {
  width: 90px;
  height: 30px;
  background-color: #fff;
  color: #00a9ff;
  font-size: 16px;
  cursor: pointer;
  border-radius: 15px;
  text-align: center;
}

.nav-wrapper {
  width: 100%;
  height: 60px;
  background-color: #f5fcff;
}

.nav {
  width: 1000px;
  margin: 0 auto;
  display: flex;
  flex: 1;
  justify-content: space-around;
  height: 60px;
  line-height: 60px;
}

.nav li {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 141px;
  text-align: center;
}

.nav li a {
  display: block;
  font-size: 16px;
}

.nav .active {
  text-align: center;
  border-radius: 15px;
}

.nav .active a {
  color: #fff;
  font-weight: 700;
  width: 94px;
  height: 34px;
  line-height: 34px;
  background-color: #00a9ff;
  border-radius: 18px;
}
</style>
